import random
import Tkinter
import tkSnack
import sys

notes = [440, 494, 523, 587, 659]

def setVolume(volume=50):
    """set the volume of the sound system"""
    if volume > 100:
        volume = 100
    elif volume < 0:
        volume = 0
    tkSnack.audio.play_gain(volume)

def playNote(freq, duration):
    """play a note of freq (hertz) for duration (seconds)"""
    snd = tkSnack.Sound()
    filt = tkSnack.Filter('generator', freq, 30000, 0.0, 'sine',(4500*duration))
    snd.stop()
    snd.play(filter=filt, blocking=1)

def soundStop():
    """stop the sound the hard way"""
    try:
        root = root.destroy()
        filt = None
    except:
        pass

root = Tkinter.Tk()
tkSnack.initializeSnack(root)


correct = True
simonstring=0
simonarray=[]
n = 0

while correct:
	rand = random.randint(0,4)
	n = n + 1
	simonstring = simonstring*10 + rand
	simonarray.append(rand)
	
	for i in range(0,n):
		playNote(notes[simonarray[i]], 1)
	print str(simonstring)
	
	input = raw_input()
	
	for j in range(0,len(input)):
		playNote(notes[int(input[j])], 1)

	playNote(0, 2)
			
	if input != str(simonstring):
		correct=False

print "FUCK YOU"
soundStop()
root.withdraw()